<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>轮播帖子管理</title>
<link rel="stylesheet" href="/layui/css/layui.css"/>
<link rel="stylesheet" href="/css/css.css"/>
	<style>
		.layui-table-body .layui-table-cell{
			height:50px;
			line-height: 50px;
		}
	</style>
</head>
<body>


	<div style="padding: 20px">
	        <span class="layui-breadcrumb">
			  <a>首页</a>
			  <a><cite>轮播帖子管理</cite></a>
			</span>
		    <div style="padding-top: 20px;">
		    	<div>
			    	<div>
			          <button class="layui-btn layuiadmin-btn-list" data-type="batchdel" onclick="addCarouselArticle()">添加</button>
			    	</div>
			    </div>
			    <div>
				    <table width="100%" id="carouselArticleListTable" ></table>
			    </div>
			</div>

	  </div>
	    
<script src="/layui/layui.js"></script>
	<script src="/js/jquery.js"></script>
	<script src="/js/common.js"></script>
<script type="text/javascript">

	layui.use(['element','form','table'], function(){
	    var form=layui.form;
		  var element = layui.element; //导航的hover效果、二级轮播帖子等功能，需要依赖element模块
		  $ = layui.jquery; // 使用jquery
		  table = layui.table;
		  
		  table.render({
		    elem: '#carouselArticleListTable'
		    ,url:'/admin/carouselArticle/list'
		    ,cols: [[
			  {type:'checkbox'}
              ,{field:'id', width:100,title: '编号'}
              ,{field:'imageName', width:200,title: '轮播图片',templet:formatImageName}
		      ,{field:'name', width:200,title: '轮播帖子名称'}
		      ,{field:'url',title: '轮播帖子地址'}
		      ,{field:'sort', width:100, title: '排列序号',align:'center'}
		      ,{field:'action', width:250, title: '操作',align:'center',templet:formatAction}
		    ]]
		  });

	});
	
	
	function deleteOne(id){
		layer.confirm('您确定要删除这条记录吗？', {
	    title:"系统提示"
		  ,btn: ['确定','取消'] //按钮
		}, function(){
			layer.closeAll('dialog');
			$.post("/admin/carouselArticle/delete",{"id":id},function(result){
				if(result.success){
					layer.msg("删除成功！");
					table.reload("carouselArticleListTable",{});
				}else{
					layer.msg("删除失败，请联系管理员！");
				}
			},"json");
		}, function(){
		  
		});
	}
	
	function addCarouselArticle(){
		layer.open({
			  type: 2,
			  title: '添加轮播帖子',
			  area: ['550px', '350px'],
			  content: '/admin/saveCarouselArticle.html' //iframe的url
			});
	}
	
	function modifyCarouselArticle(id){
		layer.open({
			  type: 2,
			  title: '修改轮播帖子',
			  area: ['550px', '350px'],
			  content: '/admin/saveCarouselArticle.html?id='+id //iframe的url
			});
	}

    function modifyCarouselArticleImage(id){
        layer.open({
            type: 2,
            title: '修改轮播帖子图片',
            area: ['500px', '500px'],
            content: '/admin/saveCarouselArticleImage.html?id='+id //iframe的url
        });
    }
	
	
	function formatAction(d){
		return "<button class='layui-btn layui-btn-normal layui-btn-xs' onclick='modifyCarouselArticleImage("+d.id+")'><i class='layui-icon layui-icon-edit'></i>修改图片</button><button class='layui-btn layui-btn-normal layui-btn-xs' onclick='modifyCarouselArticle("+d.id+")'><i class='layui-icon layui-icon-edit'></i>编辑</button><button class='layui-btn layui-btn-warm layui-btn-xs' onclick='deleteOne("+d.id+")'><i class='layui-icon layui-icon-delete' ></i>删除</button>";
	}

    function formatImageName(d) {
        return "<img  src='/carouselImages/"+d.imageName+"'/>";
    }



</script>
</body>
</html>